//
//  UIView+BorderRadius.m
//  AmountBody
//
//  Created by smm on 2018/1/4.
//  Copyright © 2018年 RCMTM. All rights reserved.
//

#import "UIView+BorderRadius.h"
#import <Masonry/Masonry.h>

@implementation UIView (BorderRadius)
#pragma mark - 加圆角边框
-(void)setYuanJiaoForRadius:(CGFloat)radius andMasks:(BOOL)masks
{
    if (masks) {
        self.layer.masksToBounds = YES;
    }
    self.layer.cornerRadius = radius;
    
}

-(void)setBianKuangAndColor:(UIColor*)color
{
    self.layer.borderWidth = 1.0;
    self.layer.borderColor = color.CGColor;
}
#pragma mark - 不定角加圆角
-(void)addLayerRectCorner:(UIRectCorner)RectCorner andRadius:(CGFloat)radius
{
    
    UIBezierPath *maskPath = [UIBezierPath bezierPathWithRoundedRect:self.bounds byRoundingCorners:RectCorner cornerRadii:CGSizeMake(radius, radius)];
    CAShapeLayer *maskLayer = [[CAShapeLayer alloc] init];
    maskLayer.frame = self.bounds;
    maskLayer.backgroundColor = (__bridge CGColorRef _Nullable)([UIColor whiteColor]);
    maskLayer.path = maskPath.CGPath;
    self.layer.mask = maskLayer;
    
}

- (UIView *)addLineOnPosition: (UIViewLinePosition)position {
    return [self addLineOnPosition:position color:[UIColor colorWithWhite:0 alpha:0.3] lineWidth:1.0f / [UIScreen mainScreen].scale insets:UIEdgeInsetsZero];
}


- (UIView *)addLineOnPosition: (UIViewLinePosition)position
                    color: (UIColor *)color
                    lineWidth: (CGFloat)lineWidth
                    insets: (UIEdgeInsets)insets {

    UIView *line = [[UIView alloc] init];
    line.backgroundColor = color;
    [self addSubview:line];
    [line mas_makeConstraints:^(MASConstraintMaker *make) {
        switch (position) {
            case UIViewLinePositionTop:
                make.left.equalTo(self).offset(insets.left);
                make.right.equalTo(self).offset(-insets.right);
                make.top.equalTo(self).offset(insets.top);
                make.height.equalTo(@(lineWidth));
                break;
            case UIViewLinePositionLeft:
                make.left.equalTo(self).offset(insets.left);
                make.top.equalTo(self).offset(insets.top);
                make.bottom.equalTo(self).offset(-insets.bottom);
                make.width.equalTo(@(lineWidth));
                break;
            case UIViewLinePositionBottom:
                make.left.equalTo(self).offset(insets.left);
                make.right.equalTo(self).offset(-insets.right);
                make.bottom.equalTo(self).offset(-insets.bottom);
                make.height.equalTo(@(lineWidth));
                break;
            default:
                make.right.equalTo(self).offset(insets.right);
                make.top.equalTo(self).offset(insets.top);
                make.bottom.equalTo(self).offset(-insets.bottom);
                make.width.equalTo(@(lineWidth));
                break;
        }
    }];
    return line;
}



@end
